-----------------------------------------------------------------------------------------------------------------------------------------
--Option信息，系统信息收集
-----------------------------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------------------------
--全局变量存储全局信息
-----------------------------------------------------------------------------------------------------------------------------------------
globalStrLLMakeListsFile = ""
globalStrSourceRoot = ""
globalStrCurrentDir = ""
globalStrRootDir = ""
globalBoolStopAtExecError = true
globalBoolLuaDebugOutputFlag = false
globalBoolMakeCleanFlag = false
globalNumberProcessors      = 1
globalStrModuleUtilities = "CommonUtilities"
globalStringCommandParseLua = "CommandParseFuncs"

globalTableCommandTable		= {}
globalTableSetVarTable			= {}
globalTableSetDataTable		= {}

globalTableTargetNameTable		= {}
globalTableTargetSrcTable		= {}
globalTableTargetTypeTable		= {}
globalTableTargetPathTable		= {}

globalTableCFLAGSTable			= {}
globalTableCXXFLAGSTable		= {}
globalTableLDFLAGSTable			= {}

globalTableMacroNameTable		= {}
globalTableMacroARGVTable		= {}
globalTableMacroTokenTable		= {}

globalTableErrorHandlerInfo		= {}


globalTableTargetDependenceTable		= {}
globalStringTargetDependenceFile = ""

globalBoolCMakeFlage			= false

globalTableIncludeDirectoriesTable	= {}

globalTableDefinitions				={}
globalTableRequiredPackageTable		={}


globalTableVariableName			= {}
globalTableVariableValue		= {}
globalTableVariableProperty		= {}


local localStrLuaName="PreParse.lua"
-----------------------------------------------------------------------------------------------------------------------------------------
--common tools 
-----------------------------------------------------------------------------------------------------------------------------------------
require(globalStrModuleUtilities)
-----------------------------------------------------------------------------------------------------------------------------------------
--读取预定义系统信息
-----------------------------------------------------------------------------------------------------------------------------------------
dofile(globalStrLLMakeHomeBinPath.."/SystemInfo.conf")

-----------------------------------------------------------------------------------------------------------------------------------------
--Option读入
-----------------------------------------------------------------------------------------------------------------------------------------
local optionString = os.getenv("LLMAKE_OPTION")
--空字符
if nil == optionString then
	optionString = ""
end
--print(optionString)

OptionTokenTable = parseOption2Token(optionString)
local srcRootString = "."
local fileNameString = "LLMakeLists.txt"
for i,v in pairs (OptionTokenTable) do 
--	print(i,v)
	if "-f" == v then
		srcRootString=OptionTokenTable[i+1]
--		print(rootString)
		if nil == srcRootString then
			globalTableErrorHandlerInfo["luaFile"] = localStrLuaName
			globalTableErrorHandlerInfo["Resean"] = "-f option wrong"
			dofile(globalStrLLMakeErrorHandler)
		end
	elseif "-C" == v then
		fileNameString = "CMakeLists.txt"
		globalBoolCMakeFlage = true
	elseif "-NS" == v then
		globalBoolStopAtExecError = false
	elseif "-log=lua" == v then
		globalBoolLuaDebugOutputFlag = true
	elseif "-clean" == v then
		globalBoolMakeCleanFlag = true
	elseif "-help" == v then
		print("-f <dir> : Give source code directory,default compile current directory")
		print("-C <dir> : Use CMakeLists.txt of CMake")
		print("-ES <dir> : Stop when meeting compile error")
		print("-log=lua : log out lua script dubug information")
		os.exit(0)
	else
--		print("Unknow Option"..v)
	end
end
-----------------------------------------------------------------------------------------------------------------------------------------
--全局变量代入
-----------------------------------------------------------------------------------------------------------------------------------------
globalStrLLMakeListsFile = srcRootString.."/"..fileNameString
globalStrSourceRoot = globalStrCurrentDir.."/"..srcRootString
globalStrRootDir = globalStrCurrentDir
-----------------------------------------------------------------------------------------------------------------------------------------
--DEBUG输出
-----------------------------------------------------------------------------------------------------------------------------------------
if globalBoolLuaDebugOutputFlag then
	print("-----global vars from Main.lua")
	print(package.path)
	print("globalStrLLMakeHomePath = ",globalStrLLMakeHomePath)
	print("globalStrLLMakeHomeScriptPath = ",globalStrLLMakeHomeScriptPath)
	print("globalStrLLMakeHomeBinPath = ",globalStrLLMakeHomeBinPath)
	print("globalNumberProcessors = ",globalNumberProcessors)
	print("-----global vars from InfoCollect.lua")
	print("globalStrLLMakeListsFile = ",globalStrLLMakeListsFile)
	print("globalStrSourceRoot = ",globalStrSourceRoot)
	print("globalStrCurrentDir = ",globalStrCurrentDir)
	print("globalStrRootDir = ",globalStrRootDir)
	print("globalBoolStopAtExecError = ",globalBoolStopAtExecError)
	print("globalBoolLuaDebugOutputFlag = ",globalBoolLuaDebugOutputFlag)
end
